package com.example.smartpark.controller;

import com.example.smartpark.common.Result;
import com.example.smartpark.dto.AnnouncementCategoryDTO;
import com.example.smartpark.service.AnnouncementCategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 管理员公告分类Controller
 */
@Slf4j
@RestController
@RequestMapping("/api/admin/announcement-categories")
public class AdminAnnouncementCategoryController {

    @Autowired
    private AnnouncementCategoryService categoryService;

    /**
     * 创建公告分类
     *
     * @param categoryDTO 分类信息
     * @return 创建后的分类
     */
    @PostMapping
    public Result<AnnouncementCategoryDTO> createCategory(@RequestBody @Valid AnnouncementCategoryDTO categoryDTO) {
        log.info("创建公告分类: {}", categoryDTO);
        AnnouncementCategoryDTO category = categoryService.createCategory(categoryDTO);
        return Result.success(category);
    }

    /**
     * 更新公告分类
     *
     * @param id 分类ID
     * @param categoryDTO 分类信息
     * @return 更新后的分类
     */
    @PutMapping("/{id}")
    public Result<AnnouncementCategoryDTO> updateCategory(
            @PathVariable Integer id,
            @RequestBody @Valid AnnouncementCategoryDTO categoryDTO) {
        log.info("更新公告分类: id={}, category={}", id, categoryDTO);
        AnnouncementCategoryDTO category = categoryService.updateCategory(id, categoryDTO);
        return Result.success(category);
    }

    /**
     * 删除公告分类
     *
     * @param id 分类ID
     * @return 操作结果
     */
    @DeleteMapping("/{id}")
    public Result<Boolean> deleteCategory(@PathVariable Integer id) {
        log.info("删除公告分类: {}", id);
        boolean result = categoryService.deleteCategory(id);
        return Result.success(result);
    }
} 